/**
 * @单位名称：飞羽个人
 * 	Copyright (c) 2017 All Rights Reserved.
 * @系统名称：测试
 * @工程名称：
 * @文件名称: 
 * @类路径: 
 */
package com.feiyu.controller;

import com.feiyu.service.HouseProjectChangeService;
import com.feiyu.service.HouseProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import com.feiyu.bean.HouseProjectChange;
import com.feiyu.common.controller.BaseController;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 
 * 
 * @see
 * @author 	nanshouxiao
 * @date	2018-5-23 17:36:42
 * @version	V1.0.0
 */
@Controller
@RequestMapping("houseProjectChange")
public class HouseProjectChangeController extends BaseController<HouseProjectChange>
{
    @Autowired
    private HouseProjectChangeService houseProjectChangeService;

    private static Pattern batchNumberPattern = Pattern.compile("总第(.*?)批");

    @PostMapping("importProjectChangeByFilepath")
    @ResponseBody
    public String importProjectChangeByFilepath(String filePath) {
        String batchNumber = this.getBatchNumber(filePath);
        houseProjectChangeService.importProjectChangeByFilepath(filePath, batchNumber);
        return "第" + batchNumber + " 批数据导入成功";

    }
    private String getBatchNumber(String fileName) {
        String result = null;
        Matcher matcher = batchNumberPattern.matcher(fileName);
        if (matcher.find()) {
            result = matcher.group(1);
        }
        return result;
    }

}